<template>
  <div class="page">
    <nav-com title="中军值转赠" :showView="true" @back="backHandler()">
      <div @click="transferList()" style="font-size: 14px;color: #F86931;">转赠记录</div>
    </nav-com>
    <div style="padding: 20px; margin-bottom: 15px">
      <div style="line-height: 50px;display: flex;justify-content: space-between;">
        <div>转出账户</div>
        
      </div>
      <div>
        <van-radio-group v-model="radio">
          <van-radio name="1" checked-color="#ff4a3e">中军值</van-radio>
        </van-radio-group>
      </div>
    </div>
    <div style="margin:0 50px;">{{userMobile}}</div>
    <div class="padd_box" style="display: flex;margin:0 20px;align-items: center;justify-content: space-between;">
      <van-col span="12">
        <div class="">
          <van-field
            label-class="label"
            :border="true"
            type="number"
            style="margin-top: 5vw"
            v-model="code"
            placeholder="请输入验证码"
          />
        </div>
      </van-col>
      <van-col span="10" style="text-align: right">
        <div
          class="login_box"
          @click="codeHandler"
          v-if="codeFalg"
          style="text-align: center; color: #ff491f"
        >
          {{ codeText }}
        </div>
        <div
          class="login_box"
          v-else
          style="text-align: center; color: #ff491f"
        >
          {{ codeText }}
        </div>
      </van-col>
    </div>
    <div style="background-color: white; padding: 20px">
      <div>
        <span>接受账号</span>
        <van-field
          label-class="label"
          :border="true"
          type="tel"
          style="margin-top: 5vw"
          v-model="mobile"
          @blur="transferUserHandler()"
          placeholder="请输入接收账户"
        />
      </div>
      <div style="color: #818181; font-size: 14px; line-height: 40px;padding-left: 20px;">
          {{userName}}
        </div>
      <div>
        <span>转出中军值</span>
        <van-field
          label-class="label"
          :border="true"
          type="number"
          style="margin-top: 5vw"
          v-model="score"
          placeholder="请输入中军值数量"
        />
      </div>
      <div>
        <div>温馨提醒</div>
        <div style="color: #818181; font-size: 14px; line-height: 40px">
          转出请核对对方姓名
        </div>
      </div>
      <div class="btn" @click="transfer">提交</div>
    </div>
  </div>
</template>
    
    <script>
import navCom from "@/component/nav";
import { Toast, RadioGroup, Radio, Field } from "vant";
import { getFttuserUserId2, scoreSubgift,postVerificationcodes,score_send,verify_mobile } from "@/api/api";
export default {
  name: "index",
  components: {
    navCom,
  },
  data() {
    return {
      userMobile:"",
      mobile: "",
      score: "",
      radio: "1",
      codeText:'获取验证码',
      codeFalg:true,
      refDisabled:false,
      code:"",
      userName:null
    };
  },
  mounted() {
    // console.log(this.$route.params);
    // this.userMobile=this.$route.params.mobile;
    this.initData()
  },
  methods: {
    backHandler() {
      this.$router.go(-1);
      // if(weixin.isAndroid()){
      //   window.JS_TROOPS.goBack()
      // }else{
      //   this.$router.go(-1);
      // }
    },
    initData(){
      getFttuserUserId2().then((res) => {
        console.log("getFttuserUserId2", res);
        if (res.data.code == 1) {
          this.userMobile = res.data.data.mobile;
        } 
      });
    },
    transferList(){
      this.$router.push({name:'transferRecord', params:{type:6}})
    },
    transferUserHandler(){
      if(!  this.mobile.trim()){
        Toast("手机号不可以为空");
      }else{
        verify_mobile({
          mobile: this.mobile
        }).then((res) => {
          console.log(res);
          if (res.data.code == 1) {
              this.userName=res.data.data.name;
          } else {
            this.$dialog.alert({
              message: res.data.msg,
            });
          }
        });
      }
     
    },
    async transfer() {
      console.log(this.$route.params.phone);
      if (!this.mobile.trim()) {
        Toast("手机号不可以为空");
      } else if (!this.score.trim()) {
        Toast("中军值未输入");
      } else if (!this.code.trim()) {
        Toast("验证码未输入");
      }else {
        this.LOADING = true;
        const res = await scoreSubgift({
          mobile: this.mobile,
          score: this.score,
          captcha:this.code
        });
        this.LOADING = false;
        console.log("scoreSubgift", res);
        Toast(res.data.msg);
        if (res.data.code == 1) {
          this.backHandler();
        }
      }
    },
    //获取验证码
    codeHandler() {
      let that = this;
      let telLen = this.userMobile.length;
      if (telLen == 11) {
        let time = null;
        clearInterval(time);
        that.codeFalg = false;
        let t = 60;
        time = setInterval(function () {
          t--;
          that.codeText = t;
          if (t <= 0) {
            that.codeText = "获取验证码";
            that.codeFalg = true;
            clearInterval(time);
          }
        }, 1000);

        score_send({
           mobile: this.userMobile
        //  mobile: "17109919660"
        }).then((res) => {
          if (res.code == 1) {
          } else {
            this.$dialog.alert({
              message: res.data.msg,
            });
          }
        });
        return true;
      } else {
        this.message = "请输入正确手机号";
        return false;
      }
    },
  },
};
</script>
    
    <style scoped>
body {
  background-color: #ffffff !important;
}
.page {
  width: 100vw;
  height: 100vh;
  background-color: white;
}
.btn {
  width: 50.6vw;
  height: 13.3vw;
  background: #f86830;
  margin: 0 auto;
  font-size: 4.5vw;
  text-align: center;
  line-height: 13.3vw;
  margin-top: 10vw;
  font-family: PingFangSC-Medium, PingFang SC;
  /*font-weight: 500;*/
  color: #ffffff;
  border-radius: 50px;
}
.label {
  font-size: 4.5vw;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #333333;
}
.van-cell {
  box-shadow: 0px 2px 8px 0px rgba(0, 0, 0, 0.14);
  border-radius: 8px;
  margin-bottom: 15px;
}

.login_box {
  border: 1px solid #F86931;
  color: #F86931;
  font-size: 4.2vw;
  border-radius: 10px;
  line-height: 45px;
}
.login_box label {
  padding-left: 5.3vw;
}
.login_box input {
  height: 11vw;
  line-height: 11vw;
  width: 50vw;
  border: none;
}
</style>